export default {
	data() {
		return {
			list: [],
			pagination: {},
			params: {
				size: 10,
				page: 1
			},
			service: '',
			isNull: false,
			isReachBottom: false
		};
	},
	methods: {
		dataNext(list) {
			if (this.pagination.page > 1) {
				this.list = this.list.concat(list);
			} else {
				this.list = list;
			}
		},
		getList(params) {
			console.log(this.service);
			this.params = {
				...params
			};
			this.service({
				...params
			})
				.then(res => {
					// console.log(res)
					let list = [];
					if (res.data) {
						this.pagination = res.data.pagination;
						list = res.data.list;
						if (res.data.pagination.total == 0) {
							this.isNull = true;
						} else {
							this.isNull = false;
						}

						this.dataNext(list);
					}
					uni.stopPullDownRefresh();
				})
				.catch(err => {
					uni.showToast({
						icon: 'none',
						title: err.message
					});
					uni.stopPullDownRefresh();
				});
		},
		// 回到顶部
		backTop() {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 0
			})
		}
	},
	onPullDownRefresh() {
		this.getList({
			...this.params,
			page: 1
		});
	},
	onReachBottom() {
		if (
			this.pagination.page * (this.pagination.pageSize || this.pagination.size) >=
			this.pagination.total
		) {
			this.isReachBottom = true;
		} else {
			this.isReachBottom = false;
			this.getList({
				...this.params,
				page: this.pagination.page + 1
			});
		}
	}
};
